import sys
from docx import Document

def append_docx(source_path, target_path, output_path):
    # Load the source and target documents
    source_doc = Document(source_path)
    target_doc = Document(target_path)
    
    # Append content from source to target
    for element in source_doc.element.body:
        target_doc.element.body.append(element)
    
    # Save the modified target document
    target_doc.save(output_path)

if __name__ == "__main__":
    if len(sys.argv) != 4:
        print("Usage: python append_docx.py <source_docx> <target_docx> <output_docx>")
        sys.exit(1)

    source_file = sys.argv[1]
    target_file = sys.argv[2]
    output_file = sys.argv[3]
    
    append_docx(source_file, target_file, output_file)
    print(f"Content from {source_file} has been appended to {target_file}. The result is saved in {output_file}.")
